﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace FrbaCommerce.Comprar_Ofertar
{
    public partial class frm_preguntar : Form
    {
        private DataRow dr_publicacion;

        public frm_preguntar(DataRow dr_publicacion)
        {
            InitializeComponent();
            this.dr_publicacion = dr_publicacion;
        }

        private void frm_preguntar_Load(object sender, EventArgs e)
        {
            btn_enviar.Enabled = false;
        }

        private void btn_enviar_Click(object sender, EventArgs e)
        {
            BaseDeDatos baseDeDatos = BaseDeDatos.Instance;
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.CommandText = "LOS_GDDES.SP_INSERTAR_PREGUNTA";
            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlCommand.Parameters.AddWithValue("@id_publicacion", dr_publicacion.Field<Decimal>("ID_PUBLICACION"));
            sqlCommand.Parameters.AddWithValue("@pregunta", txt_pregunta.Text);
            sqlCommand.Parameters.AddWithValue("@id_usuario_pregunta", BaseDeDatos.Instance.idUsuario);
            sqlCommand.Parameters.AddWithValue("@fecha_pregunta", Convert.ToDateTime(Properties.Settings.Default.FechaDelSistema));
            baseDeDatos.ejecuta(sqlCommand);
            this.Close();
        }

        private void btn_cancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_pregunta_TextChanged(object sender, EventArgs e)
        {
            if (txt_pregunta.Text != "")
                btn_enviar.Enabled = true;
            else
                btn_enviar.Enabled = false;
        }


    }
}
